from flask import jsonify


def response_success(code=0, msg='', data=None):
    response_data = {
        'code': code,
        'msg': msg,
        'data': data
    }
    return jsonify(response_data)


def response_fail(code = 500, msg='', data=None):
    response_data = {
        'code': code,
        'msg': msg,
        'data': data
    }
    return jsonify(response_data)


def response_page(msg: str = "", data=None, total=None, page=None, per_page=None,total_pages=None):
    """ 动态表格渲染响应 """
    res = {
        'msg': msg,
        'code': 0,
        'data': data,
        'total': total,
        'page': page,
        'per_page': per_page,
        'total_page':total_pages
    }

    return jsonify(res)
